﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using QXGameEngine.Logic;
using System.Collections.Generic;

namespace QXGameEngine.Control {

    public partial class QXMiniMap : UserControl {

        /// <summary>
        /// Mini地图控件
        /// </summary>
        public QXMiniMap() {
            InitializeComponent();
            TelescopicTip.Text = "收缩";
            Head.Fill = new ImageBrush() { ImageSource = Super.GetImage("/Image/Interface/Plate/MiniMapHead.png") };
            Body.Background = new ImageBrush() { ImageSource = Super.GetImage("/Image/Interface/Plate/MiniMapBody.png") };
            Telescopic.Fill = new ImageBrush() { ImageSource = Super.GetImage("/Image/Icon/6.png") };
            Panorama.Fill = new ImageBrush() { ImageSource = Super.GetImage("/Image/Icon/8.png") };
            BodyMaskImage.ImageSource = Super.GetImage("/Image/Interface/Plate/MiniMapMask.png");
            Narrow.Fill = new ImageBrush() { ImageSource = Super.GetImage("/Image/Icon/9.png") };
            Zoom.Fill = new ImageBrush() { ImageSource = Super.GetImage("/Image/Icon/10.png") };
        }

        /// <summary>
        /// 获取或设置身体是否可见
        /// </summary>
        public Visibility BodyVisibility {
            get { return Body.Visibility; }
            set { Body.Visibility = value; }
        }

        /// <summary>
        /// 获取或设置题头文字
        /// </summary>
        public string VSName {
            get { return SName.Text; }
            set { SName.Text = value; }
        }

        /// <summary>
        /// 获取或设置当前地图名字
        /// </summary>
        public string VMapName {
            get { return MapName.Text; }
            set { MapName.Text = value; }
        }

        /// <summary>
        /// 获取或设置处于屏幕中的X位置
        /// </summary>
        public double Left {
            get { return (double)this.GetValue(Canvas.LeftProperty); }
            set { this.SetValue(Canvas.LeftProperty, value); }
        }

        /// <summary>
        /// 获取或设置处于屏幕中的Y位置
        /// </summary>
        public double Top {
            get { return (double)this.GetValue(Canvas.TopProperty); }
            set { this.SetValue(Canvas.TopProperty, value); }
        }

        /// <summary>
        /// 获取或设置层次深度
        /// </summary>
        public int ZIndex {
            get { return (int)this.GetValue(Canvas.ZIndexProperty); }
            set { this.SetValue(Canvas.ZIndexProperty, value); }
        }

        /// <summary>
        /// 获取或设置主角当前X坐标
        /// </summary>
        public string X {
            get { return CoordinateX.Text; }
            set { CoordinateX.Text = value; }
        }

        /// <summary>
        /// 获取或设置主角当前Y坐标
        /// </summary>
        public string Y {
            get { return CoordinateY.Text; }
            set { CoordinateY.Text = value; }
        }

        /// <summary>
        /// 获取或设置地图原始宽
        /// </summary>
        public int MapOriginalWidth { get; set; }

        /// <summary>
        /// 获取或设置地图原始高
        /// </summary>
        public int MapOriginalHeight { get; set; }

        /// <summary>
        /// 获取或设置缩放比例
        /// </summary>
        public double Scaling {
            get { return (double)GetValue(ScalingProperty); }
            set { SetValue(ScalingProperty, value); }
        }
        public static readonly DependencyProperty ScalingProperty = DependencyProperty.Register(
            "Scaling",
            typeof(double),
            typeof(QXMiniMap),
            new PropertyMetadata(ChangeScalingProperty)
        );
        private static void ChangeScalingProperty(DependencyObject d, DependencyPropertyChangedEventArgs e) {
            QXMiniMap obj = (QXMiniMap)d;
            Image miniMapBack = obj.FindName("MiniMapImage") as Image;
            miniMapBack.Width = obj.MapOriginalWidth / (double)e.NewValue;
            miniMapBack.Height = obj.MapOriginalHeight / (double)e.NewValue;
            obj.Multiples.Text = string.Format("{0}X", obj.Scaling.ToString());
        }

        /// <summary>
        /// 获取或设置缩放最小值
        /// </summary>
        public int MinScaling { get; set; }

        /// <summary>
        /// 获取或设置缩放最大值
        /// </summary>
        public int MaxScaling { get; set; }

        //鼠标左键点击
        private void UserControl_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {
            //如果点到伸缩按钮
            if (e.OriginalSource == Telescopic) {
                if (TelescopicTip.Text == "展开") {
                    BodyVisibility = Visibility.Visible;
                    Telescopic.Fill = new ImageBrush() { ImageSource = Super.GetImage("/Image/Icon/6.png") };
                    TelescopicTip.Text = "收缩";
                } else {
                    BodyVisibility = Visibility.Collapsed;
                    Telescopic.Fill = new ImageBrush() { ImageSource = Super.GetImage("/Image/Icon/7.png") };
                    TelescopicTip.Text = "展开";
                }
            } else if (e.OriginalSource == Narrow) {
                if (Scaling > MinScaling) { Scaling -= 1; }
            } else if (e.OriginalSource == Zoom) {
                if (Scaling < MaxScaling) { Scaling += 1; }
            } else if (e.OriginalSource == Panorama) {

            }
            e.Handled = true;
        }

    }
}
